<?php

session_start();

include_once "src/controller/blmanagement/AuthorizationAccountManagement.php";
include_once "src/controller/blmanagement/UserAccountManagement.php";
include_once "src/model/User.php";
include_once "src/misc/ClientReponseGenerator.php";

try {
    
    $email = $_POST["email"];
    $pswd = $_POST["password"];
    
    $user = UserAccountManagement::getUserByEmail($email);

    if (AuthorizationAccountManagement::login($email, $pswd)) {
        $_SESSION["email"] = $email;
        $_SESSION["username"] = $user->getName();
        echo ClientReponseGenerator::simpleJsonResponse(1, "", "");
    } else {
        throw new Exception();
    }

} catch (Exception $e) {
    echo ClientReponseGenerator::simpleJsonResponse(0, "AuthenticateUserException", "");
}

?>
